package rule03;

import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author ChangLiang
 * @date 2020/3/16
 */
public final class SingletonObject4 {

    /**
     * 类里面有很多引用 也比较重
     */
    Connection conn;

    Socket socket;

    private static SingletonObject4 instance;

    private SingletonObject4(){
        try {
            // 初始化connection
            this.conn = DriverManager.getConnection("jdbc://mysql");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        // 初始化socket
        this.socket = new Socket();
    }

    public static SingletonObject4 getInstance() {
        if (null == instance) {
            synchronized (SingletonObject4.class) {
                if (null == instance) {
                    instance = new SingletonObject4();
                }
            }
        }
        return instance;
    }
}
